package javagamecontroller.activities.controllers;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.LinearLayout;
import com.javagamecontroller.R;


/**
 * A frame for a controller that only has buttons and no other special
 * components. You specify the layout through a ButtonManager.
 * You can reskin the background by passing in an integer reference to the
 * drawable resource that should be used for this layout.
 * 
 * @author Ben Schwab
 * 
 */
public class GridController extends ControllerFrame {

    public static final String BUTTON_MANAGER = "button_manager";
    public static final String BACKGROUND = "background";

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid_controller);
        GridView gridview = (GridView) findViewById(R.id.grid_view);
        Bundle extras = getIntent().getExtras();
        String buttonLayout = extras.getString(BUTTON_MANAGER);
        int backgroundResource = extras.getInt(BACKGROUND);
        if (backgroundResource != 0) {
            LinearLayout background = (LinearLayout) findViewById(R.id.grid_controller_background);
            background.setBackgroundResource(backgroundResource);
        }
        initializeButtonManager(buttonLayout);
        if (getButtonManager() != null) {
            gridview.setAdapter(getButtonManager());
        }

    }

}
